package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.School;
import cn.wolfcode.crm.mapper.SchoolMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ISchoolService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class SchoolServiceImpl implements ISchoolService {

    @Autowired
    private SchoolMapper schoolMapper;

    //保存和更新员工操作
    public int saveOrUpdate(School record) {
        if (record.getId() == null) {
            return schoolMapper.insert(record);
        } else {
            return schoolMapper.updateByPrimaryKey(record);
        }
    }

    public School selectByPrimaryKey(Long id) {
        return schoolMapper.selectByPrimaryKey(id);
    }


    //学校列表操作
    public List<School> selectAll() {
        return schoolMapper.selectAll();
    }


    /**
     * 删除操作
     * @param id
     */
    public void delete(Long id) {
        schoolMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageResult query(QueryObject qo) {
        int count = schoolMapper.queryCount(qo);
        if (count == 0) {
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<School> data = schoolMapper.queryList(qo);
        return new PageResult(count, data);
    }
}
